<html xmlns="http://www.w3.org/1999/xhtml">
<div class="row subsystem-header">
    <div class="pull-left">
        <span style="font-size: 14px;">批次历史信息查询</span>
    </div>
</div>
<div class="row subsystem-toolbar">
    <div style="height: 44px; line-height: 44px;display: inline;">
        <span class="pull-left"
              style="height: 30px; line-height: 30px; margin-top: 7px;display: inline;">&nbsp;项目：</span>
        <select class="form-control pull-left" id="h-dispatch-batch-history-domain-list"
                style="width: 180px;height: 24px; line-height: 24px; margin-top: 10px;padding: 0px;">
        </select>
    </div>
    <div class="pull-right" id="h-dispatch-batch-history-toolbar-list">
        <button class="btn btn-info btn-sm" onclick="DispatchBatchHistoryObj.refresh()" title="编辑机构信息">
            <span class="icon-refresh"> 刷新</span>
        </button>
        <button class="btn btn-danger btn-sm" onclick="DispatchBatchHistoryObj.delete()" title="删除机构信息">
            <span class="icon-trash"> 删除</span>
        </button>
    </div>
</div>
<div class="row">
    <div class="col-sm-12 col-md-12 col-lg-12" id="h-dispatch-batch-history-table-info">
        <table data-page-list="[20,30,50,100]"
               data-page-size="30"
               data-pagination="true"
               data-search="false"
               data-side-pagination="client"
               data-striped="true"
               data-toggle="table"
               data-toolbar-align="right"
               data-unique-id="sid"
               data-url="/v1/dispatch/history"
               id="h-dispatch-batch-history-info-table-details">
            <thead>
            <tr>
                <th data-checkbox="true" data-field="state"></th>
                <th data-align="center" data-formatter="DispatchBatchHistoryObj.formatterindex">序号</th>
                <th data-align="center" data-field="codeNumber" data-sortable="true">批次编码</th>
                <th data-field="batchDesc" data-sortable="true">批次描述</th>
                <th data-align="center" data-field="batchStatusDesc" data-sortable="true">批次状态</th>
                <th data-align="center" data-field="asOfDate" data-sortable="true">批次日期</th>
                <th data-align="center" data-field="startTime" data-sortable="true">开始日期</th>
                <th data-align="center" data-field="endTime" data-sortable="true">结束时间</th>
                <th data-align="center" data-formatter="DispatchBatchHistoryObj.calcCost" data-sortable="true">运行时长</th>
                <th data-field="retMsg">退出消息</th>
                <th data-align="center" data-formatter="DispatchBatchHistoryObj.formatter">操作</th>
            </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">
    var DispatchBatchHistoryObj = {
        $table: $('#h-dispatch-batch-history-info-table-details'),
        formatterindex: function (value, row, index) {
            return index + 1;
        },
        formatter: function (value, row, index) {
            return '<span class="h-td-btn btn-success btn-xs" onclick="DispatchBatchHistoryObj.getGroupHistory(\'' + row.sid + '\',\'' + row.batchDesc + '\')"> 详细信息</span>';
        },
        calcCost: function (value, row, index) {
            /*<![CDATA[*/
            var start = new Date(row.startTime.substr(0, 19));
            var end = new Date(row.endTime.substr(0, 19));

            var diff = (end - start) / 1000;

            if (diff < 0) {
                diff = 0;
            }
            var costTime = diff + "s";

            if (diff >= 60) {
                if (diff % 60 != 0) {
                    costTime = (diff % 60).toFixed(0) + "s";
                }
                // 转换成分钟
                diff = (diff / 60).toFixed(0);
                if (diff >= 60) {
                    if (diff % 60 != 0) {
                        costTime = (diff % 60).toFixed(0) + "m " + costTime;
                    }
                    // 转换成小时
                    diff = (diff / 24).toFixed();
                    if (diff >= 24) {
                        if (diff % 24 != 0) {
                            costTime = (diff % 60).toFixed(0) + "h " + costTime;
                        }
                        costTime = (diff % 24).toFixed(0) + "d" + costTime;
                    } else {
                        costTime = diff + "h " + costTime;
                    }
                } else {
                    costTime = diff + "m " + costTime;
                }
            }
            /*]]>*/
            return costTime;
        },
        getGroupHistory: function (uuid, BatchDesc) {
            Hutils.openTab({
                url: "/v1/dispatch/batch/group/monitoring/page",
                id: "hzwy23##groupBatchMonitoringPage",
                data: {uuid: uuid, batch_desc: BatchDesc},
                title: BatchDesc + " 任务组状态",
            })
        },
        refresh: function () {
            $("#h-dispatch-batch-history-info-table-details").bootstrapTable('refresh');
        },
        delete: function () {
            var row = $("#h-dispatch-batch-history-info-table-details").bootstrapTable('getSelections');
            if (row.length == 0) {
                $.Notify({
                    message: "您没有选择需要编辑的批次历史信息",
                    type: "info",
                })
                return
            }

            var json = new Array();
            $(row).each(function (index, element) {
                var e = {};
                e.sid = element.sid;
                json.push(e);
            });

            $.Hconfirm({
                body: "点击确定,删除批次历史信息",
                callback: function () {
                    $.HAjaxRequest({
                        url: "/v1/dispatch/history/delete",
                        type: "POST",
                        data: {JSON: JSON.stringify(json)},
                        success: function () {
                            $.Notify({
                                message: "删除批次历史信息成功",
                                type: "success",
                            });
                            $(row).each(function (index, element) {
                                DispatchBatchHistoryObj.$table.bootstrapTable("removeByUniqueId", element.sid);
                            })
                        },
                    })
                }
            })
        },
    };
    $(document).ready(function () {
        var hwindow = document.documentElement.clientHeight;
        $("#h-dispatch-batch-history-table-info").height(hwindow - 130);

        $.getJSON("/v1/auth/domain/self/owner", function (data) {
            var arr = new Array();
            $(data.owner_list).each(function (index, element) {
                var ijs = {};
                ijs.id = element.domain_id
                ijs.text = element.domain_desc
                ijs.upId = "####hzwy23###"
                arr.push(ijs)
            });

            $("#h-dispatch-batch-history-domain-list").Hselect({
                data: arr,
                height: "24px",
                width: "180px",
                value: data.domain_id,
                onclick: function () {
                    $("#h-dispatch-batch-history-info-table-details").bootstrapTable('refresh');
                },
            });

            $("#h-dispatch-batch-history-info-table-details").bootstrapTable({
                height: hwindow - 130,
                queryParams: function (params) {
                    params.domain_id = $("#h-dispatch-batch-history-domain-list").val();
                    return params;
                }
            });
        });
    });

</script>
</html>